import java.lang.reflect.Array;
import java.util.Arrays;

public class shuzu {
    public static void main(String[] args) {
        //拷贝
        int[] arr1={4,2,7,8,5};
        int[]  arr2=Arrays.copyOf(arr1,4);
        System.out.println(Arrays.toString(arr2));
    }

    public static void main9(String[] args) {
        //填充
        int[] arr=new int[10];
        //Arrays.fill(arr,9);
        Arrays.fill(arr,4,7,9);//[4,7)填充为9
        System.out.println(Arrays.toString(arr));
    }


    public static void main8(String[] args) {
        //判断数组是否相等
        int[] arr1={1,2,3,4,5,6,7};
        int[] arr2={1,2,3,4,5,6,7};

        boolean ret = Arrays.equals(arr1, arr2);
        System.out.println(ret);



    }


    public static void main7(String[] args) {
        //查找
        int[] arr={1,2,3,4,5,6,7};
        int ret=Arrays.binarySearch(arr,2,5,3);
        //[2,5)之间找3的下标
        System.out.println(ret);
    }




    public static void main6(String[] args) {
    //冒泡排序
        int[] arr={3,2,5,6,1};
        int i=0,j=0;
        int tmp=0;
        for(i=0;i<arr.length-1;i++){
            for(j=0;j<arr.length-1-i;j++){
                if(arr[j]>arr[j+1]){
                    tmp=arr[j+1];
                    arr[j+1]=arr[j];
                    arr[j]=tmp;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }



    public static void main5(String[] args) {
        //二分查找
        int[] arr={1,3,6,7,8,9};
        int left=0;
        int right=arr.length-1;

        int find=7;//要查找的值
        while(left<=right){
            int tmp=(left+right)/2;
            if(arr[tmp]<find){
                left=tmp+1;
            }else if(arr[tmp]>find){
                right=tmp-1;
            }else{
                System.out.println("下标为："+tmp);
                break;
            }
        }

    }




    public  static String myToString(int[] arr){
        String ret="[";
        int i=0;
        for(i=0;i<arr.length;i++){
            ret+=arr[i];
            if(i!=arr.length-1){
                ret+=",";

            }
        }
       ret+="]";
        return ret;
    }
    public static void main4(String[] args) {
        int[] arr={1,2,3,4};
        String ret=myToString(arr);
        System.out.println(ret);
    }



    public static void main3(String[] args) {
        //让不知道数组里面有什么是，用null
        int[] arr=null;
        System.out.println(arr[0]);
    }

    public static void main2(String[] args) {
        //遍历数组
        int[] arr={1,2,3,4};
        int len=arr.length;//求数组的长度
       //1.打印
        for(int i=0;i<arr.length;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.println();
       //2.打印
        for(int x:arr){//拿到arr的值就放到x中
            System.out.print(x+" ");
        }

        System.out.println();

       //把传入的数组转化为字符串的形式输出
        String ret= Arrays.toString(arr);
        System.out.println(ret);


    }
    public static void main1(String[] args) {
        int[] arr={1,2,3,4};

        int[] arr2=new int[3];//默认是0

        int[] arr3=new int[]{1,2,3,4};


        boolean[] bool=new boolean[3];//默认是

    }


}
